<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 17-2-23
 * Time: 下午2:16
 */

class MyClass
{
    const constant = 'constant value';
    const HERDOC = <<<her
function showConstant() {
        echo  self::constant . "\\n";
        echo  \$this::constant . "\\n";
    }
her;
    const NOWDOC = <<<'now'
function showConstant() {
        echo  self::constant . "\n";
        echo  $this::constant . "\n";
    }
now;

    function showConstant() {
        echo  self::constant . "\n";
        echo  $this::constant . "\n";
    }

    public static function showConstant2() {
        echo  self::constant . "\n";
    }
}

echo MyClass::constant . "\n";

$classname = "MyClass";
echo $classname::constant . "\n"; // 自 5.3.0 起

$class = new MyClass();
$class->showConstant();

echo $class::constant."\n"; // 自 PHP 5.3.0 起

MyClass::showConstant2();
echo MyClass::HERDOC;
echo MyClass::NOWDOC;



abstract class dbObject
{
    const TABLE_NAME='undefined';

    public static function GetAll()
    {
        ///////////////////////
        $c = get_called_class();
        echo $c.PHP_EOL;
        return "SELECT * FROM `".$c::TABLE_NAME."`";
    }

    public static function getPar(){
        echo __CLASS__.PHP_EOL;
    }
}

class dbPerson extends dbObject
{
    const TABLE_NAME='persons';

    public static function getPar()
    {
        parent::getPar();
    }
}

class dbAdmin extends dbPerson
{
    const TABLE_NAME='admins';
    public static function getPar()
    {
        get_parent_class()::getPar();
    }
}

echo dbPerson::GetAll().PHP_EOL;//output: "SELECT * FROM `persons`"
echo dbAdmin::GetAll().PHP_EOL;//output: "SELECT * FROM `admins`"

dbAdmin::getPar();
dbPerson::getPar();


print_r((bool)get_magic_quotes_gpc());

class A {
    const MY_CONST = 'AAAA';
    public function my_const_self() {
        return self::MY_CONST;
    }
    public function my_const_static() {
        return static::MY_CONST;
    }
    public function my_const_this() {
        return $this::MY_CONST;
    }
}

class B extends A {
    const MY_CONST = "BBBB";

    public function my_const_self() {
        return parent::my_const_self();
    }
    public function my_const_static() {
        return parent::my_const_static();
    }
    public function my_const_this() {
        return parent::my_const_this();
    }
}

$b = new B();
echo $b->my_const_self();//AAAA
echo $b->my_const_static();///BBBB
echo $b->my_const_this();///BBBB


class MyClass2
{
    const ABC = array('A', 'B', 'C');
    const A = '1';
    const B = '2';
    const C = '3';
    const NUMBERS = array(
        self::A,
        self::B,
        self::C,
    );
}
var_dump(MyClass2::ABC);
var_dump(MyClass2::NUMBERS);


class AA{
    const X=1;
    const Y=self::X;
    const Z=BB::X;
}
class BB extends AA{
    const X=1.0;
}
var_dump(BB::Y); // float(1)
var_dump(BB::X); // double(1)
var_dump(BB::Z); // double(1)